package sis.studentinfo;

import java.util.ArrayList;
import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * Provide a representation of a single-semester
 * session of a specific university course.
 * @author gunho
 */
public class CourseSession implements Comparable<CourseSession> {
	static final String NEWLINE = System.getProperty("line.separator");
	static final String ROSTER_REPORT_HEADER = "Student" + NEWLINE + "-" + NEWLINE;
	static final String ROSTER_REPORT_FOOTER = NEWLINE + "# students = ";
	private static int count;
	private String department;
	private String number;
	private ArrayList<Student> students = new ArrayList<Student>();
	private Date startDate;
	private int numberOfCredits;
	
	/*
	public CourseSession (String department, String number) {
		this.department = department;
		this.number = number;
	}
	*/
	void setNumberOfCredits(int numberOfCredits) {
		this.numberOfCredits = numberOfCredits;
	}
	
	private CourseSession (String department, String number, Date startDate) {
		this.department = department;
		this.number = number;
		this.startDate = startDate;
	}
	
	public static CourseSession create(String department, String name, Date startDate) {
		incrementCount();
		return new CourseSession(department, name, startDate);
	}
	
	public String getDepartment() {
		return department;
	}
		
	public String getNumber() {
		return number;
	}  
	
	int getNumberOfStudents() {
		return students.size();
	}
	
	static void resetCount() {
		count = 0;
	}
	
	static int getCount() {
		return count;
	}
	
	private static void incrementCount() {
		count = count + 1;
	}
	
	public void enroll (Student student) {
		student.addCredits(numberOfCredits);
		students.add(student);
	}
		
	Student get(int index) {
		return students.get(index);
	}
	
	public ArrayList<Student> getAllStudents() {
		return students;
	}
	
	Date getEndDate() {
		GregorianCalendar calendar = new GregorianCalendar();
		calendar.setTime(startDate);
		int numberOfDays = 16 * 7 -3;
		calendar.add(Calendar.DAY_OF_YEAR, numberOfDays);
		return calendar.getTime();
	}
	
	Date getStartDate() {
		return startDate;
	}

	public int compareTo(CourseSession that) {
		int compare = this.getDepartment().compareTo(that.getDepartment());
		if (compare == 0)
			compare = this.getNumber().compareTo(that.getNumber());
		return compare;
		//return this.getDepartment().compareTo(that.getDepartment());
	}
}